<?php

use common\components\Wechat\Wechat;

$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

return [
    'id' => 'app-api',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'api\controllers',
    'language' => 'zh-CN',
    'bootstrap' => ['log'],
    'modules' => require(__DIR__ . '/modules.php'),
    'components' => [
        'wechat' => [
            'class' => common\components\Wechat\Wechat::className(),
            'agentReturnUrl' => "{$params['config']['wechat']['authReturnUrl']}?r={$params['config']['wechat']['hostUrl']}{$params['config']['wechat']['returnRoute']}",
        ],
        'request' => [
            'class' => 'cza\base\components\web\Request',
            'noCsrfRoutes' => [
                'eshop/cashapply/default/cash-apply',
                'activity/record/record/send-money',
                'eshop/custom-service/allowance-form',
                'eshop/custom-service/audit-succ'
            ],
            'csrfParam' => '_csrf-api',
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'DB0uq8cLjtKgh6YYwm4cEZmXEQNrTZav',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        'user' => [
            'identityClass' => 'common\models\c2\entity\FeUserModel',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-api', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'advanced-api',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                'apiLog' => [
                    'class' => 'yii\log\FileTarget',
                    'logFile' => "@runtime/logs/api_info.log",
                    'categories' => ['application'],
                    'levels' => ['info', 'trace'],
                    // belows setting will keep the log fresh
                    'maxFileSize' => 0,
                    'maxLogFiles' => 0,
                ],
                'apiSql' => [
                    'class' => 'yii\log\FileTarget',
                    'logFile' => "@runtime/logs/api_sql.log",
                    'categories' => ['yii\db\*'],
                    'levels' => ['info'],

                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
            ],
        ],
    ],
    'params' => $params,
];
